package producer_consumer;

public class Producer implements Runnable {
    @Override
    public void run() {
        while (true) {
            WareHouse.lock.lock();

            if(WareHouse.mark){
                //有包子，等待，唤醒消费者吃
                try {
                    WareHouse.producer.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }else{
                //没包子，生产
                System.out.println("生产者生产包子");
                WareHouse.mark = true;
                WareHouse.consumer.signal();
            }


            WareHouse.lock.unlock();
        }

    }
}
